﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class admin_manageNews : System.Web.UI.Page
{
    
    db_news news = new db_news();
    protected void Page_Load(object sender, EventArgs e)
    {
        Server.Execute("inc/checkPurview.aspx");  // 此处用户权限验证
        DataSet ds = new DataSet();
        ds = news.selectNewsALL();
        //if (selectId == "0")
        //{
        //    //ds = news.selectNewsALLKind();
        //}
        //else if (selectId.Equals("1"))
        //{
        //    ds = news.selectNewsTopKind("1");
        //}
        //else if (selectId.Equals("2"))
        //{
        //    ds = news.selectNewsTopKind("2");
        //}
        //else if (selectId.Equals("3"))
        //{
        //    ds = news.selectNewsTopKind("3");
        //}
        //else if (selectId.Equals("4"))
        //{
        //    ds = news.selectNewsTopKind("4");
        //}
        //ds = news.selectNewsALL();
        //分页 开始 -------
        int CurPage;
        if (Request.QueryString["Page"] != null && Convert.ToInt32(Request.QueryString["Page"]) > 0)
            CurPage = Convert.ToInt32(Request.QueryString["Page"]);
        else
            CurPage = 1;
        PagedDataSource ps = new PagedDataSource();
        try
        {
            ps.DataSource = ds.Tables[0].DefaultView;

            ps.AllowPaging = true;
            //每个页面显示的条数
            ps.PageSize = 10;
            onePage.Text = ps.PageSize.ToString();
            //求数据的总数
            allMsg.Text = ps.DataSourceCount.ToString();
            ps.CurrentPageIndex = CurPage - 1;
            //求总页
            allPages.Text = ps.PageCount.ToString();
            nowPage.Text = CurPage.ToString();
            //将数据源与控件绑定
            newsList.DataSource = ps;
            newsList.DataBind();
        }
        catch { }
        //上一页
        if (!ps.IsFirstPage)
        {
            firstPage.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=1";
            prePage.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage - 1);
        }
        //下一页
        if (!ps.IsLastPage)
        {
            nextPage.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage + 1);
            endPage.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(ps.PageCount);
        }
        //分页 结束 -------
    }
}